define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
            index: function () {
                var companyinfo= Config.companyinfo;
                if(companyinfo==1){
                    var url='kupay/compay';
                    Backend.api.addtabs(url, '公司信息', 'fa fa-cubes');
                }
                // 初始化表格参数配置
                $("#c-timingtime").on("dp.change", function () {
                    var yera = $(this).val();
                    var year1 = $("#year1").val();
                    if (yera != year1) {
                        $("#year1").val(yera);
                        $("#datetimes").submit();
                    }

                    //回调事件
                });
                $(document).on("change", "#c-flag", function () {
                    var dates = $(this).val();
                    var year2 = $("#year2").val();
                    $("#year2").val(dates);
                    $("#datetimes").submit();
                });
                Controller.api.bindevent();
            },
            info: function () {
                layer.closeAll()
                $("#search").click(function(){
                    $("#datetimes").submit();
                })
                $(".detail-type-button").click(function () {
                    var types = $(this).data('info');
                    $("#type").val(types);
                    $("#types").submit();
                });

                $("#allchongfa").click(function () {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    var type = $('#type').val();
                    var id = $('#id').val();
                    var pages=1;
                    var listnum= Config.count;
                    function sends(){
                        var pagesnum=Math.ceil(listnum/10);
                        var m=(pages-1)*10+1;
                        var n=10*pages
                        if(n>listnum){
                            n=listnum;
                        }
                        layer.msg('正在发送第'+m+'到'+n+'条', {time: 0, icon:16});
                        //发信息
                        $.ajax({
                            type: 'POST',
                            url: "kupay/paylog/sendsoneall",
                            data: {id: id,page:pages,limit:10,type:type},
                            success: function (info) {
                                pages=pages+1;
                                if(pages<=pagesnum){
                                    sends();
                                } else{
                                    layer.closeAll();
                                    layer.msg(info.msg)
                                    setTimeout(function () {
                                        location.reload();
                                    }, 2000);
                                    //发信息
                                }
                            }
                        });

                    }
                    sends();
                });
                $("#allchongfaerr").click(function () {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    var type = $('#type').val();
                    var id = $('#id').val();
                    var pages=1;
                    var listnum= Config.count1;
                    function sends(){
                        var pagesnum=Math.ceil(listnum/10);
                        var m=(pages-1)*10+1;
                        var n=10*pages
                        if(n>listnum){
                            n=listnum;
                        }
                        layer.msg('正在发送第'+m+'到'+n+'条', {time: 0, icon:16});
                        //发信息
                        $.ajax({
                            type: 'POST',
                            url: "kupay/paylog/sendsoneallerr",
                            data: {id: id,page:pages,limit:10,type:type},
                            success: function (info) {
                                pages=pages+1;
                                if(pages<=pagesnum){
                                    sends();
                                } else{
                                    layer.closeAll();
                                    layer.msg(info.msg)
                                    setTimeout(function () {
                                        location.reload();
                                    }, 2000);
                                    //发信息
                                }
                            }
                        });

                    }
                    sends();

                });
                $("#exports").click(function () {
                    var id = $('#id').val();
                    var type = $('#type').val();
                    if(id!=''){
                        window.location.href = 'exports?id='+id+'&type='+type;
                    } else {
                        layer.closeAll()
                    }


                });
                $(".chongfa").click(function () {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    var type = $(this).data('type');
                    var id = $(this).data('id');
                    $.ajax({
                        type: 'POST',
                        url: "kupay/paylog/sendsone",
                        data: {id: id, type: type},
                        success: function (info) {
                            layer.closeAll()
                            if (info.code == 1) {
                                layer.msg(info.msg)
                                setTimeout(function () {
                                    location.reload();
                                }, 2000);

                            } else {
                                layer.msg(info.msg)
                            }

                        }
                    });
                })

                Controller.api.bindevent();
            }
            ,
            infoedit: function () {
                $("#save").click(function () {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        type: 'POST',
                        url: "kupay/setlog/infosave",
                        data: $('#forms').serialize(),
                        success: function (info) {
                            layer.closeAll()
                            if (info.code == 1) {
                                layer.msg(info.msg)
                                setTimeout(function () {
                                    location.reload();
                                }, 2000);

                            } else {
                                layer.msg(info.msg)
                            }

                        }
                    });
                })

                Controller.api.bindevent();
            }
            ,
            add: function () {
                Controller.api.bindevent();
            }
            ,
            edit: function () {
                Controller.api.bindevent();
            }
            ,
            api: {
                bindevent: function () {
                    Form.api.bindevent($("form[role=form]"));
                }
            }
        }
        ;
    return Controller;
});
